<p class="Paragraph">FileNumber: Any integer expression that defines the file to write into.</p>
<p class="Paragraph">Position: For relative files (random access files) the number of the record to be written.</p>
<p class="Paragraph">For binary files (binary access) the byte position in the file at which to begin writing.</p>
<p class="Paragraph">Variable: Name of the variable to write to the file.</p>
<p class="Paragraph">Note for relative files: If the contents of this variable do not match the length of a record specified in the <span class="T1">Len</span> <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>clause of the <span class="T1">Open</span> statement, the space from the end of the new written data to the next record is padded with the existing data in the file.</p>
<p class="Paragraph">Note for binary files: The contents of the variables is written to the specified position, and the file pointer is set directly after the last byte, without any space between records.</p>
<p class="P2">Example:</p>
<p class="PropText">Sub ExampleRandomAccess</p>
<p class="PropText">Dim iNumber As Integer</p>
<p class="PropText">Dim sText As Variant REM Must be a variant type</p>
<p class="PropText">Dim aFile As String</p>
<p class="PropText">aFile = "c:\data.txt"</p>
<p class="PropText"/>
<p class="PropText">iNumber = Freefile</p>
<p class="PropText">Open aFile For Random As #iNumber Len=32</p>
<p class="PropText">Seek #iNumber,1 <text:s text:c="2" xmlns:text="http://openoffice.org/2000/text"/>REM Position to start writing</p>
<p class="PropText">Put #iNumber,, "This is the first line of text" <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>REM Fill line with text</p>
<p class="PropText">Put #iNumber,, "This is the second line of text"</p>
<p class="PropText">Put #iNumber,, "This is the third line of text"</p>
<p class="PropText">Seek #iNumber,2</p>
<p class="PropText">Get #iNumber,,sText</p>
<p class="PropText">Print sText</p>
<p class="PropText">Close #iNumber</p>
<p class="PropText"/>
<p class="PropText">iNumber = Freefile</p>
<p class="PropText">Open aFile For Random As #iNumber Len=32</p>
<p class="PropText">Get #iNumber,2,sText</p>
<p class="PropText">Put #iNumber,,"This is new text"</p>
<p class="PropText">Get #iNumber,1,sText</p>
<p class="PropText">Get #iNumber,2,sText</p>
<p class="PropText">Put #iNumber,20,"This is the text in record 20"</p>